package database

import (
	"bytes"
	"database/sql"
	"time"
)

//MSSQLDB MSSQLDB实现
type MSSQLDB struct {
}

//LoadDataByTable 从表或着视图中获取数据
func (c *MSSQLDB) LoadDataByTable(tableName string, columns []string, orderColName, direction string) (*sql.Rows, error) {
	return loadDataByTable(tableName, columns, orderColName, direction)
}

//LoadDataBySQL 通过SQL语句获取数据
func (c *MSSQLDB) LoadDataBySQL(sqlstr string, params ...interface{}) (*sql.Rows, error) {
	return loadDataBySQL(sqlstr, params...)
}

//LoadDataByProc 通过存储过程获取数据
func (c *MSSQLDB) LoadDataByProc(procName string, params ...interface{}) (*sql.Rows, error) {
	var buff bytes.Buffer
	buff.WriteString("exec ")
	buff.WriteString(procName)
	buff.WriteString(" ")
	pLen := len(params)
	for i := 0; i < pLen; i++ {
		buff.WriteString("?,")
	}
	if pLen > 0 {
		buff.Truncate(buff.Len() - 1)
	}
	return loadDataBySQL(buff.String(), params...)
}

//GetStartEndTime 获取系统追溯时间
func (c *MSSQLDB) GetStartEndTime() (*time.Time, *time.Time, error) {
	return getStartEndTime()
}
